let curUnionID = null;
let curUid = null;

function createList(pageNo = 1, pageSize = 10) {
    let matchData = {};
    matchData.uid = curUid;
    matchData["unionID"] = curUnionID;

    var start = (pageNo - 1) * pageSize;
    apiAdminGetRecord("userScoreDataModel", start, pageSize, matchData, function (data) {
        if (data.code === 0) {
            if (data.code === 0) {
                setTimeout(() => {
                    data.msg.recordArr.sort((a, b) => b.dayTime - a.dayTime);
                    $('#dataList').bootstrapTable('load', data.msg);
                }, 200)

            }
        }
    });
}

$(document).ready(function () {
    var parameters = parseQueryString(window.location.href);
    curUnionID = parameters.unionID;
    curUid = parameters.uid;
    //数据表格初始化
    $('#dataList').bootstrapTable({
        showRefresh: true,
        striped: true, // 是否显示行间隔色
        pageNumber: 1, // 初始化加载第一页
        pagination: true, // 是否分页
        sidePagination: 'server', // server:服务器端分页|client：前端分页
        pageSize: 10, // 单页记录数
        pageList: [10, 20, 30],
        theadClasses: "thead-light", //这里设置表头样式
        totalField: "totalCount",
        smartDisplay: false,
        buttonsClass: 'light',
        buttonsPrefix: 'btn',
        dataField: "recordArr",
        maintainSelected: true,
        showRefresh: false, // 刷新按钮
        onPageChange: function (number, size) {
            createList(number, size);
        },
        queryParams: function (params) { // 上传服务器的参数
            var temp = { //如果是在服务器端实现分页，limit、offset这两个参数是必须的
                limit: params.limit, // 每页显示数量
                offset: params.offset, // SQL语句起始索引
            };
            return temp;
        },
        columns: [{
            title: 'id',
            field: '_id',
            visible: false
        },
        {
            title: '联盟ID',
            align: "center",
            valign: "middle",
            field: 'unionID',
        },
        {
            title: '战绩',
            align: "center",
            valign: "middle",
            field: 'score',
        },
        {
            title: '局数',
            align: "center",
            valign: "middle",
            field: 'count',
        },
        {
            title: '时间',
            align: "center",
            valign: "middle",
            field: 'dateTime'
        }
        ]
    });
    $('#dataList').bootstrapTable('hideLoading');
    createList(1);
});



function dateMatter(value, row, index) {
    return new Date(value).toLocaleString();
}

function scoreMatter(value, row, index) {
    if (value) {
        return value.toFixed(2);
    } else {
        return 0;
    }

}

function gameTypeMatter(value, row, index) {

    if (value >= 1) {
        return enumeration.gameName[value]
    }
    else {
        return "其他"
    }

}

function changeTypeMatter(value, row, index) {
    if (value === enumeration.scoreChangeType.GIVE) {
        return "赠送分数";
    } else if (value === enumeration.scoreChangeType.MODIFY_LOW) {
        return "给下级改分";
    } else if (value === enumeration.scoreChangeType.MODIFY_UP) {
        return "被上级改分";
    } else if (value === enumeration.scoreChangeType.GAME_WIN) {
        return "赢分";
    } else if (value === enumeration.scoreChangeType.GAME_START_UNION_CHOU) {
        return "门票";
    } else if (value === enumeration.scoreChangeType.GAME_WIN_CHOU) {
        return "赢家抽分";
    } else if (value === enumeration.scoreChangeType.SAFE_BOX) {
        return "返利提取";
    } else if (value === enumeration.scoreChangeType.UNION_SERVICE) {
        return "联盟服务费";
    } else if (value === enumeration.scoreChangeType.FIX_SCORE) {
        return "保底";
    } else if (value === enumeration.scoreChangeType.SAVE_BOX) {
        return "保险柜操作";
    }
}